--[[

	Copyright (c) 2012-2020 baby-bus.com

	TODO:   Main
	Author: DemonYao
	Date:   2020.10.09
 
	http://www.babybus.com/ 

]] 




--------------------------
-- 引入命名空间
--------------------------
-- local BaseLayer = import("app.common.layer.BaseLayer")




--[[
	类
--]]


local M = classLayerTouch("Main")

local WEAPON_RIGHT_LIST = {"weapon_1004_r", "weapon_1004b_r", "weapon_1004c_r", "weapon_1004d_r", "weapon_1004e_r"}



--------------------------
-- 构造函数
--------------------------

function M:ctor(params)
	-- [超类调用]
	M.super.ctor(self, params)
	-- [本类调用]
	-- 左边武器
	self.leftWeaponIndex     = 0
	-- 右边武器
    self.rightWeaponIndex    = 0
	self.logoText            = nil

end	

--------------------------
-- 渲染
--------------------------

function M:onRender()
	-- [超类调用]
	M.super.onRender(self)

	-- [本类调用]
	-- 加载节点
	self:loadChangeBonesData()
	self:loadNodes()
end

-- 加载节点
function M:loadNodes()
	local armature = self:createNode("Armature", {
		dragonBonesDataFile		= "mecha_1004d_show/mecha_1004d_show_ske.json", 
		dragonBonesTexFile	    = "mecha_1004d_show/mecha_1004d_show_tex.json",
		armatureName			= "mecha_1004d",
		animName				= "idle"
	}):p(400, 200):to(self)
	self.armature = armature
end

-- 加载换装的骨骼数据
function M:loadChangeBonesData()
	dragonBones.CCFactory:loadDragonBonesData("weapon_1004_show/weapon_1004_show_ske.json")
	dragonBones.CCFactory:loadTextureAtlasData("weapon_1004_show/weapon_1004_show_tex.json")
end

-- 加载渲染以外的其他操作
function M:onEnterTransitionFinish()
	--
end

function M:replaceDisplay(index)
	if index == -1 then
		self.rightWeaponIndex = self.rightWeaponIndex + 1 
		if self.rightWeaponIndex > T.count(WEAPON_RIGHT_LIST) then
			self.rightWeaponIndex = 1
		end
		local  displayName    = WEAPON_RIGHT_LIST[self.rightWeaponIndex]
		dragonBones.CCFactory:replaceSlotDisplay("weapon_1004_show", "weapon", "weapon_r", displayName, 
		self.armature:getArmature():getSlot("weapon_hand_r"));
	elseif index == 1 then
		self.leftWeaponIndex = self.leftWeaponIndex + 1
		self.leftWeaponIndex = self.leftWeaponIndex % 5
		self.armature:getSlot("weapon_hand_l"):setDisplayIndex(self.leftWeaponIndex)
	else
		local logoSlot = self.armature:getSlot("logo");
		if (logoSlot:getDisplay() == self.logoText) then
			print("111111111111111111111==", logoSlot:getRawDisplay(), tolua.type(logoSlot:getRawDisplay()))
			logoSlot:setDisplay(logoSlot:getRawDisplay())
		else 
			print("222222222222222222", self.logoText, tolua.isnull(self.logoText))
			self.logoText = cc.Label:create()
			self.logoText:setString("Core Element")
			logoSlot:setDisplay(self.logoText)
		end
	end
end


--------------------------
-- 触控
-------------------------- 

function M:onTouchBegan(x, y, touches)
	--  触控有效
	if x <= 300 then
		self:replaceDisplay(-1)
	elseif x >= 600 then
		self:replaceDisplay(1)
	else
		self:replaceDisplay(0)
	end
	return true 
end

function M:onTouchMoved(x, y, touches)
	--   
end

function M:onTouchEnded(x, y, touches)
	--  
end



--------------------------
-- 功能函数
--------------------------




--------------------------
-- 属性
--------------------------




--------------------------
-- 父类重写
--------------------------




----------------------------------------------------
-- 析构
--------------------------

function M:onDestructor()
	-- [超类调用]
	M.super.onDestructor(self)
	-- [本类调用]

end








return M






